#ifndef OSIRIS_H
#define OSIRIS_H

#include "rknn_api.h"
#include <mutex>


#include "opencv2/core/core.hpp"

static void dump_tensor_attr(rknn_tensor_attr *attr);
static unsigned char *load_data(FILE *fp, size_t ofst, size_t sz);
static unsigned char *load_model(const char *filename, int *model_size);
static int saveFloat(const char *file_name, float *output, int element_size);

struct InferenceResult {
    bool has_target;   // 是否识别到目标
    cv::Mat result;    // 结果图像（可选）
    int window_id;          // 编号：1~6
    uint64_t frame_id;      // 原图帧序号
    float prop = -1.0f;      // 最大置信度
    int x1 = 0, y1 = 0;
    int x2 = 0, y2 = 0;
    uint64_t target_roi_x, target_roi_y;
};

struct WindowInput {
    cv::Mat window_img;     // 切图图像
    int window_id;          // 编号：1~6
    uint64_t frame_id;      // 原图帧序号
    uint64_t target_roi_x, target_roi_y;
};

class osiris
{
private:
    int ret;
    std::mutex mtx;
    std::string model_path;
    unsigned char *model_data;

    rknn_context ctx;
    rknn_input_output_num io_num;
    rknn_tensor_attr *input_attrs;
    rknn_tensor_attr *output_attrs;
    rknn_input inputs[1];

    int channel, width, height;
    int img_width, img_height;

    float nms_threshold, box_conf_threshold;

public:
    osiris(const std::string &model_path);
    int init(rknn_context *ctx_in, bool isChild);
    rknn_context *get_pctx();
    InferenceResult infer(const WindowInput &input);
    ~osiris();
};

#endif